/**
 * @return {[type]}
 */
;$(function(){
	
		$('.ajax-post').click(function(){
			var target, query, form;
			var target_form = $(this).attr('target-form');
			var that = this;
			var need_confirm = false;
			if( $(this).attr('operation') == 'submit' || (target = $(this).attr('url')) || (target = $(this).attr('href'))){
				form = $('.'+target_form);
				if(form.get(0) == undefined){
					return false;
				}
				if(form.get(0).nodeName == 'FORM'){
					if($(this).hasClass('confirm')){
						if(!confirm('确认操作？')){
							return false;
						}	
					}
					if($(this).attr('url') !== undefined){
						target = $(this).attr('url');
					}else{
						target = form.get(0).action;
					}
					query = form.serialize()
				}else if(form.get(0).nodeName == 'INPUT'){
					if($(this).hasClass('confirm')){
						if(!confirm('确认操作？')){
							return false;
						}	
					}
					query = form.serialize();
				}
				$.ajax({
		            url: target,
		            type: 'post',
		            data: query,
		            dataType: 'json',
		            success: function(res) {
		                if(res.status == 1){
		                	alert('success');
		                	if(res.url != undefined){
		                		window.location.href = res.url;
		                	}else{
		                		window.location.reload();
		                	}
		                }else{
		                	alert(res.msg);
		                }
		            }
		        });
			}
			return false;
		})

		//ajax get请求
    $('.ajax-get').click(function(){
        // alert(12);
        var target;
        var that = this;
        if ( $(this).hasClass('confirm') ) {
            if(!confirm('确认要执行该操作吗?')){
                return false;
            }
        }
        if ( (target = $(this).attr('href')) || (target = $(this).attr('url')) ) {
            $.get(target).success(function(res){
                if(res.status == 1){
                	alert('success');
                	if(res.url != undefined){
                		window.location.href = res.url;
                	}else{
                		window.location.reload();
                	}
                }else{
                	alert(res.msg);
                }
    		});
        }
        return false;
    });
		// 侧边栏高亮
		function highlight_sidebar(){		
			var url = $('input[name=highlight_bar]').val();	
			var group_obj = $('.sidebar-nav').find('a[href="'+url+'"]').closest('.accordion-group');
			group_obj.find('.switch').removeClass('collapsed');
			group_obj.find('.accordion-body').addClass('collapse in').css('height','auto');
		}
		// 顶部菜单高亮
		function highlight_menu(){
			var url = $('input[name=highlight_menu]').val();	
			$('.top-menu').find('a[href="'+url+'"]').addClass('active');
		}
		highlight_menu();
		highlight_sidebar();

		$('.widget-buttons a.collapse').click(function(){
			if($(this).attr('data-collapsed') == 'false'){
				$(this).closest('.widget').find('.widget-body').slideUp();
				$(this).attr('data-collapsed', 'true').addClass('widget-hidden');
			}else{
				$(this).closest('.widget').find('.widget-body').slideDown();
				$(this).attr('data-collapsed', 'false').removeClass('widget-hidden');
			}
		});

		// 列表全选的实现
		$(".check-all").click(function(){
			$(".ids").prop("checked", this.checked);
		});

	
	
})
